<template>
	<view class="" style="padding-bottom: 150rpx;">
		<view class="mainpadding">
			<view class="flexbetween">
				<view class="" @click="jumper('/pages_message/fensi')">
					<view class="iconxx">
						<image src="../static/image/sysem/fs.png" mode=""></image>
					</view>
					<view class="strongtext xiaohui textcenter margin_top2">粉丝</view>
				</view>
				<view class="" @click="jumper('/pages_message/pinglun')">
					<view class="iconxx">
						<image src="../static/image/sysem/pl.png" mode=""></image>
					</view>
					<view class="strongtext xiaohui textcenter margin_top2">评论</view>
				</view>
				<view class="" @click="jumper('/pages_message/dianzan')">
					<view class="iconxx">
						<image src="../static/image/sysem/dz.png" mode=""></image>
					</view>
					<view class="strongtext xiaohui textcenter margin_top2">点赞</view>
				</view>
				<view class="" @click="jumper('/pages_message/shouyi')">
					<view class="iconxx">
						<image src="../static/image/sysem/sy.png" mode=""></image>
					</view>
					<view class="strongtext xiaohui textcenter margin_top2">收益</view>
				</view>
				<view class="" @click="jumper('/pages_message/xitongtongzhi')">
					<view class="iconxx">
						<image src="../static/image/sysem/xttz.png" mode=""></image>
					</view>
					<view class="strongtext xiaohui textcenter margin_top2">系统通知</view>
				</view>
			</view>
			<view class="margin_top4 titletext xiaobai">聊天列表</view>
			<view class="chatItemMessage margin_top" v-for="item in chatList" :key="item.id" @click="enterchat(item)">
				<view class="imageBox">
					<image :src="item.firend.avatar_text" mode="">
					</image>
				</view>
				<view class="right">
					<view class="nameTime">
						<view class="flexleft">
							<view class="name">{{item.firend.nickname}}</view>
							<view class="number" v-if="item.noread_num">{{item.noread_num}}</view>
						</view>
						<view class="time" v-if="item.new_content">{{item.new_content.createtime_text}}</view>
					</view>
					<template v-if="item.new_content">
						<view class="bottom yihang" v-if="item.new_content.data_type==1">{{item.new_content.message}}</view>
						<view class="bottom yihang" v-if="item.new_content.data_type==2">[图片]</view>
						<view class="bottom yihang" v-if="item.new_content.data_type==3">[视频]</view>
					</template>
				</view>
			</view>
		</view>
		<tabbar :current="3"  ref="tabbardiref"></tabbar>
	</view>
</template>

<script>
	import WebSocket from '@/static/websocket.js' //websocket封装
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				user_id: "",
				chatList: [],
				websocket: null,
			}
		},
		onLoad() {
			uni.hideTabBar()
			uni.$on("updatechatFnList", data => {
				console.log("触發方法了會话列表哈哈哈");
				this.init()
			})
		},
		onShow() {
			setTimeout(()=>{
				this.$refs.tabbardiref.noreadNum = 0
				this.$refs.tabbardiref.getnoreadNum()
			},100)
			if (httpRequest.checkIsLogin()) {
				this.user_id = uni.getStorageSync("user_id")
				this.init()
			}
		},
		onUnload() {
			uni.$off('updatechatFnList')
		},
		methods: {
			init() {
				httpRequest.request('/api/user/getChatList', 'GET', {}).then(res => {
					this.chatList = res.data
				})
			},
			enterchat(item) { //进入聊天
				let data = {
					firend_id: item.firend_id,
					friend_name: item.firend.nickname,
					firend_avatar_text: item.firend.avatar_text
				}
				uni.navigateTo({
					url: "/pages_message/chat?msg=" + encodeURIComponent(JSON.stringify(data))
				})
			},
			jumper(url) {
				uni.navigateTo({
					url: url
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	// 聊天消息

	.chatItemMessage {
		display: flex;
		margin-bottom: 40rpx;

		.imageBox {
			width: 114rpx;
			min-width: 114rpx;
			height: 114rpx;
			border-radius: 50%;
			overflow: hidden;
			margin-right: 40rpx;

			image {
				width: 100%;
				height: 100%;
			}
		}

		.right {
			flex: 1;
		}

		.nameTime {
			display: flex;
			justify-content: space-between;

			.name {
				font-size: 32rpx;
				font-family: PingFang SC-Medium, PingFang SC;
				font-weight: 500;
				color: #fff;
				margin-right: 10rpx;
			}

			.number {
				width: 34rpx;
				height: 34rpx;
				line-height: 34rpx;
				text-align: center;
				background: #FF526A;
				border-radius: 50%;
				font-size: 20rpx;
				font-family: PingFang SC-Medium, PingFang SC;
				font-weight: 500;
				color: #FFFFFF;
			}

			.time {
				font-size: 24rpx;
				font-family: PingFang SC-Medium, PingFang SC;
				font-weight: 500;
				color: #666666;
			}
		}

		.bottom {
			font-size: 26rpx;
			font-family: PingFang SC-Medium, PingFang SC;
			font-weight: 500;
			color: #999999;
			margin-top: 35rpx;
		}
	}

	.tiaos {
		width: 34rpx;
		height: 34rpx;
		background: #FF526A;
		border-radius: 50%;
		font-size: 20rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 500;
		color: #FFFFFF;
	}

	.touxiang {
		width: 98rpx;
		height: 98rpx;
		border-radius: 50%;
	}

	.iconxx {
		width: 88rpx;
		height: 88rpx;

		image {
			width: 100%;
			height: 100%;
		}
	}
</style>